-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#1668] API types to simplify work with launch configuration attributes #1669
base: master
Are you sure you want to change the base?
Conversation
ruspl-afed
commented
Dec 19, 2024
•
edited
Loading
edited
- identify launch attribute
- connect it with preference metadata (to supply defaults/label/description)
- read attribute from configuration
- write attribute to configuration working copy
- demonstrate usage for ExternalTools
This pull request changes some projects for the first time in this development cycle.
An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch. Git patch
Further information are available in Common Build Issues - Missing version increments. |
As mentioned in the call, some example using this API proposal would be helpful. There is probably some content in org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/launchConfigurations you can tweak to leverage this API. |
ceac906
to
0eaee71
Compare
I'm not sure why it is is failing @HannesWell
|
It looks like your change is breaking API-tools^^ |
Thank you @HannesWell for your assistance.
WOW! But that wasn't part of my plan. It looks like this issue was already reported. Interesting, may be I can have a deeper look to it soon. And still interested in your feedback regarding PR content. |
After supporting |
ok, a few more days for discussion and I'm going to merge it |
Thank you for that fix/enhancement of API-tools! It's much appreciated.
Sorry for not responding. It has been some busy days recently. I have not forgotten this, just didn't have the time for it. |
* identify launch attribute * connect it with preference metadata (to supply defaults/label/description) * read attribute from configuration * write attribute to configuration working copy * demonstrate usage for ExternalTools
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a more detailed look at it and understand the goal and see the benefits from this: Better type-safety and more convenient read and writes.
Nevertheless I'm not sure that these benefits really carry the weight of the change, because currently the new API surface is very big.
Below I made some suggestion to make the API more compact, maybe we can then achieve a sufficiently got relation of advantages to API surface.
With these suggestions we would end up with just the LaunchAttributeIdentity
and LaunchAttributeDefined
types. Maybe we could even 'inline' the former into the latter and would then still get benefits mentioned above.
And eventually just having an ILaunchAttribute
interface added with a few static factories to create them is something that could indeed be a in my opinion suitable addition.
public record LauchAttributeIdentityRecord(String id) implements LaunchAttributeIdentity { | ||
|
||
/** | ||
* Convenience way to compose full qualified name for launch attribute | ||
* | ||
* @param qualifier usually corresponds to Bundle-Symbolic-Name | ||
* @param key short key to name this very attribute in the scope of | ||
* qualifier | ||
*/ | ||
public LauchAttributeIdentityRecord(String qualifier, String key) { | ||
this(qualifier + "." + key); //$NON-NLS-1$ | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a local record in a static factory method on the LaunchAttributeIdentity
type? Then this impl would be fully internal and we don't have to repeat the type in the name.
And this type name has a typo: Lauch
instead of Launch
.
* | ||
* @since 3.23 | ||
*/ | ||
public interface LaunchAttributeDefined<V> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion this would better be named either
public interface LaunchAttributeDefined<V> { | |
public interface LaunchAttributeDefinition<V> { |
or just
public interface LaunchAttributeDefined<V> { | |
public interface LaunchAttribute<V> { |
* | ||
* @since 3.23 | ||
*/ | ||
public final class LaunchAttributeProbe<V> implements Supplier<Optional<V>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this class really necessary? To me it looks like a wrapper of a LaunchAttributeRead that takes care of the exception handling.
I suggest to let LaunchAttributeRead.get/read()
return that Optional<V>
public V get() throws CoreException { | ||
if (String.class.equals(type)) { | ||
return type.cast(configuration.getAttribute(id, String.class.cast(value.get()))); | ||
} | ||
if (Boolean.class.equals(type)) { | ||
return type.cast(configuration.getAttribute(id, Boolean.class.cast(value.get()))); | ||
} | ||
if (Integer.class.equals(type)) { | ||
return type.cast(configuration.getAttribute(id, Integer.class.cast(value.get()))); | ||
} | ||
if (List.class.equals(type)) { | ||
return type.cast(configuration.getAttribute(id, List.class.cast(value.get()))); | ||
} | ||
if (Map.class.equals(type)) { | ||
return type.cast(configuration.getAttribute(id, Map.class.cast(value.get()))); | ||
} | ||
if (Set.class.equals(type)) { | ||
return type.cast(configuration.getAttribute(id, Set.class.cast(value.get()))); | ||
} | ||
throw new CoreException(Status.error(id, new ClassCastException())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we avoid this entire class when instead this method would be added as a read(ILaunchConfiguration)
method to LaunchAttributeDefined
?
public void accept(ILaunchConfigurationWorkingCopy working) { | ||
if (String.class.equals(type)) { | ||
working.setAttribute(id, String.class.cast(value.get())); | ||
} else if (Integer.class.equals(type)) { | ||
working.setAttribute(id, Integer.class.cast(value.get()).intValue()); | ||
} else if (Boolean.class.equals(type)) { | ||
working.setAttribute(id, Boolean.class.cast(value.get()).booleanValue()); | ||
} else if (List.class.equals(type)) { | ||
working.setAttribute(id, List.class.cast(value.get())); | ||
} else if (Map.class.equals(type)) { | ||
working.setAttribute(id, Map.class.cast(value.get())); | ||
} else if (Set.class.equals(type)) { | ||
working.setAttribute(id, Set.class.cast(value.get())); | ||
} else { | ||
working.setAttribute(id, value.get()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here:
Couldn't we avoid this entire class when instead this method would be added as a write(ILaunchConfiguration)
and write(ILaunchConfiguration, V value)
method to LaunchAttributeDefined
?
import org.eclipse.debug.core.LaunchAttributeDefined; | ||
import org.eclipse.debug.core.LaunchAttributeIdentity; | ||
|
||
public final class LaunchAttributeArguments implements LaunchAttributeDefined<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we replace this entire class by a static field LaunchAttributeDefined<String>LAUNCH_ATTRIBUTE_ARGUMENTS
e.g in the IExternalToolConstants
class? Implemented either with an anonymous implementation for each field or a static factory method (that contains it).
I wonder the same for the companion LaunchAttributeDefined
implementations.
if (String.class.equals(type)) { | ||
return type.cast(configuration.getAttribute(id, String.class.cast(value.get()))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we have this if-chain in the constructor and then encapsulate the action into a lambda and just execute it here?